<template>
  <div>
    <el-form ref="form" :model="form" inline>
      <el-form-item label="姓 名" style="font-weight:bold;">
        <el-input v-model="form.userName" placeholder="请输入姓名" style="width:150px;" clearable></el-input>
      </el-form-item>
      <el-form-item label="学 号" style="font-weight:bold;">
        <el-input v-model="form.userNum" placeholder="请输入学号" style="width:150px;" clearable></el-input>
      </el-form-item>
      <el-form-item label="检查人" style="font-weight:bold;">
        <el-input v-model="form.operator" placeholder="请输入" style="width:150px;" clearable></el-input>
      </el-form-item>
      <el-button size="small" class="search_button" type="primary" icon="el-icon-search" @click="getForm">查询</el-button>
      <el-button size="small" class="reset_button" icon="el-icon-refresh" @click="reset">重置</el-button>
    </el-form>
    <el-button size="small" type="success" plain icon="el-icon-download" @click="exportList">导出检查信息</el-button>
    <el-divider></el-divider>


    <el-table :data="tableData" border size="medium">
      <el-table-column prop="userName" label="姓名" align="center">
      </el-table-column>
      <el-table-column prop="userNum" label="学号" align="center">
      </el-table-column>
      <el-table-column prop="info" label="违纪情况" align="center">
      </el-table-column>
      <el-table-column prop="operator" label="检查人" align="center">
      </el-table-column>
      <el-table-column prop="createTime" label="检查日期" align="center">
      </el-table-column>
      <el-table-column label="照片" align="center">
        <template slot-scope="scope">
          <el-button size="mini" type="text" icon="el-icon-search" @click="showImg(scope.row.imgUrl)">查看</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination class="pagination" background layout="total, sizes, prev, pager, next, jumper" :total="total"
      :page-size="10" :page-sizes="[10, 20, 30, 40]" @current-change="handleCurrentChange"
      @size-change="handleSizeChange"></el-pagination>


    <el-dialog title="查看照片" :visible.sync="showPic" width="50%">
      <el-image style="width:200px" :src="picUrl" :preview-src-list="srcList" rel="no-referrer"></el-image>
    </el-dialog>
  </div>
</template>

<script>
import { getForm, exportList } from '_api/DormManage/PersonRule/index.js'
export default {
  data() {
    return {
      showPic: false,
      picUrl: "",
      srcList: [],
      showDetail: false,
      form: {
        current: 0,
        pageSize: 10,
        userName: "",
        userNum: "",
        operator: ""
      },
      tableData: [],
      total: 0,
      timeNow: ""
    }
  },

  created() {
    this.getForm()
  },
  methods: {
    showImg(e) {
      this.srcList = []
      this.showPic = true
      this.picUrl = e
      this.srcList.push(e)
    },

    //重置
    reset() {
      this.form = {
        current: 0,
        pageSize: 10,
        userName: "",
        userNum: "",
        operator: ""
      },
        this.getForm()
    },
    //当前页
    handleCurrentChange(e) {
      this.form.current = (e - 1) * 10
      this.getForm()
    },
    handleSizeChange(e) {
      this.form.pageSize = e
      this.getForm()
    },
    //获取当前时间
    getCurrentTime() {
      var _this = this;
      let yy = new Date().getFullYear();
      let mm = new Date().getMonth() + 1;
      let dd = new Date().getDate();
      let hh = new Date().getHours();
      let mf = new Date().getMinutes() < 10 ? '0' + new Date().getMinutes() : new Date().getMinutes();
      let ss = new Date().getSeconds() < 10 ? '0' + new Date().getSeconds() : new Date().getSeconds();
      _this.gettime = yy + '-' + mm + '-' + dd + ' ' + hh + ':' + mf + ':' + ss;
      this.timeNow = _this.gettime
    },
    exportList() {
      exportList(this.form).then(res => {
        const link = document.createElement('a')  //创建a标签
        const blob = new Blob([res.data], { type: 'application/vnd.ms-excel' }) //设置文件流
        link.style.display = 'none'// 设置连接
        link.href = URL.createObjectURL(blob)  //将文件流转化为blob地址
        this.getCurrentTime()
        link.download = '个人违纪报表_' + this.timeNow
        document.body.appendChild(link) // 模拟点击事件
        link.click()  //设置点击事件
        this.$message.success('导出成功！')
      })
    },

    //查询列表信息
    getForm() {
      getForm(this.form).then(res => {
        if (res.data.success == true) {
          this.tableData = res.data.data.list
          this.total = res.data.data.total
        } else {
          this.tableData = res.data.data
          this.total = ""
          this.$message.info(res.data.message)
        }
      })
    },
  }
}
</script>

<style lang="scss" scoped>
.pagination {
  float: right;
  margin-top: 10px;
}
</style>